home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4106 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.4 KB  |  84 lines

  1. Path: uni-duisburg.de!news
  2. From: mauch@uni-duisburg.de (Michael Mauch)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: BC++ v4.02 : Huge memory model pointers
  5. Date: Sun, 28 Jan 1996 03:18:21 +0100
  6. Organization: Gesamthochschule Duisburg
  7. Distribution: world
  8. Message-ID: <3108c510.203552@news.uni-duisburg.de>
  9. References: <4cqt38$ce@hickory.soton.ac.uk>
  10. NNTP-Posting-Host: slip1.uni-duisburg.de
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. jcridge <jcridge@mail.soton.ac.uk> wrote:
  14.  
  15. > If I compile and link using the huge memory model option in "Project Options", do I actually 
  16. > need to use the 'huge' keyword anywhere in my program, or does the compiler/linker take care of 
  17. > all this ? I would hope that the answer to the latter is 'yes', otherwise it seems I will have 
  18. > to do alot of extra typing when swithcing memory models... 
  19.  
  20. I'm afraid the answer is 'yes'. Compile the following test program
  21. using the huge memory model:
  22.  
  23. #include <stdio.h>
  24. #include <alloc.h>
  25.  
  26. // #define DYNAMIC_TEST
  27. // #define huge
  28.  
  29. int main(int argc, char* arg[])
  30. {
  31.   unsigned long i;
  32.   FILE* f;
  33.  
  34. #ifdef DYNAMIC_TEST
  35.   char huge* s;
  36.   s=(char huge*)farcalloc(200000UL,1);
  37. #else
  38.   static char huge s[200000UL];
  39. #endif
  40.  
  41.   f=fopen("hugeary.ary","wb");
  42.   for(i=0;i<200000UL;i++)
  43.    fprintf(f,"%c",s[i]);       /* printing 200000  00's */
  44.   fclose(f);
  45.  
  46.   for(i=0;i<200000UL;i++)
  47.    s[i]=(char)((i%10UL)+'0');  /* setting up the array to s.th.*/
  48.   s[200000UL-1]='\0';          /* setting the end of string marker */
  49.  
  50.   f=fopen("hugeary.ptr","wb");
  51.   {
  52.     char huge* p;
  53.     for(p=s;*p;p++)
  54.      fprintf(f,"%c",*p);       /* printing the array (199999 bytes) */
  55.     /*
  56.        works ok with BC++ 3.1;
  57.        with BC++ 4.01, it works only if 's' is on the heap
  58.        (i.e. DYNAMIC_TEST is #define'd)
  59.        - so much about compiler "upgrades" 
  60.     */
  61.   }
  62.   fclose(f);
  63.  
  64.   f=fopen("hugeary.str","wb");
  65.   fprintf(f,"%Fs",s);  /* this one won't work, not even with "%Fs" */
  66.   fclose(f);
  67. }
  68.  
  69. This program is supposed to write three files, each one about 200KB in
  70. size. Try it and #define "huge" and/or "DYNAMIC_TEST".
  71.  
  72. So the point is: you have to use "huge" for each array larger than 64K
  73. and for each pointer that could point to something larger than 64K -
  74. and even then you can't be sure. The run-time library does not support
  75. huge arrays/pointers, neither.
  76.  
  77. > Either way, does anyone know of any reason why a call to 'getch()' might crash the system under 
  78. > the huge memory model option ? 
  79.  
  80. No, sorry.
  81.  
  82. Regards...
  83.         Michael
  84.